from django.db import models
from rest_framework import serializers
from user.models import User
# Create your models here.
# 系统角色类
class Role(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=30, null=True, verbose_name="角色名称")
    code = models.CharField(max_length=100, null=True, verbose_name="角色权限字符串")
    create_time = models.DateField(null=True, verbose_name="创建时间")
    update_time = models.DateField(null=True, verbose_name="更新时间")
    remark = models.CharField(max_length=500, null=True, verbose_name="备注")
    class Meta:
        db_table = "role"

class RoleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Role
    fields = '__all__'
# 系统用户角色关联类
class UserRole(models.Model):
    id = models.AutoField(primary_key=True)
    role = models.ForeignKey(Role, on_delete=models.PROTECT)
    user = models.ForeignKey(User, on_delete=models.PROTECT)
    class Meta:
        db_table = "user_role"

class UserRoleSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserRole
        fields = '__amll__'
